package setting

import (
	"io"
	"log"
	"os"
)

type GinSetting struct {
	DIRPath    string
	PrefixURL  string
	URLKey     string
	UploadPath string
	DeletePath string
	MkdirPath  string
	MD5Path    string
	Host       string
	Port       int
}
type MD5Calc struct {
	State int
}

var Setting = GinSetting{}
var MD5Running = MD5Calc{}

func init() {
	Setting.URLKey = "path"
	Setting.UploadPath = "/uploadFile"
	Setting.DeletePath = "/deleteFile"
	Setting.MkdirPath = "/mkdir"
	Setting.MD5Path = "/md5"
	MD5Running.State = 0

	file := "./" + "message" + ".log"
	logFile, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
	if err != nil {
		panic(err)
	}
	// 定义多个写入器
	writers := []io.Writer{
		logFile,
		os.Stdout}
	fileAndStdoutWriter := io.MultiWriter(writers...)
	log.SetOutput(fileAndStdoutWriter) // 将文件设置为log输出的文件
	log.SetPrefix("[fileServer]")
	log.SetFlags(log.LstdFlags | log.Lshortfile | log.LUTC)
	return
}

func SetSetting(dir, url, host string, port int) {
	Setting.DIRPath = dir
	Setting.PrefixURL = url
	Setting.Host = host
	Setting.Port = port
}
